<?php
defined('SYSPATH') OR die('No Direct Script Access');
session_name('curriculo');
@session_start();
include "application/classes/validator/ValidadorDeFormularioDeAreaDeInteresse.php";
include "application/classes/visualizacao/FormularioDeAreaDeInteresse.php";

Class Controller_GerenciadorDeAreaDeInteresse extends Controller_TemplatePadrao
{

	public $errors = array();
	public $camposDoFormulario;
	public $sheets = array('reset' => 'screen', 'main' => 'screen');
	public $formularioDeAreaDeInteresse;

	function action_index(){
		$_SESSION['pagina_corrente'] = "areadeinteresse";
		if(isset($_SESSION['areaDeInteresse'])){
			$areaDeInteresse = unserialize($_SESSION['areaDeInteresse']);
			$this->formularioDeAreaDeInteresse = new FormularioDeAreaDeInteresse($areaDeInteresse);
		}
		else{
			$this->formularioDeAreaDeInteresse = new FormularioDeAreaDeInteresse();
		}

		$this->carregarFormulario();
	}
	
	function carregarFormulario(){
		$ko3_inner               = array();
		$ko3                     = array();
		$this->template->title   = 'Psicopuc WWW Ver. 3.0';
		View::set_global('x', 'Esta e uma variavel global');
		$ko3_inner['content']    = 'Dados(Exemplo)';
		$ko3['content']          = 'Dados2(Exemplo)';
		$this->template->menu    = View::factory('blocks/menu_formulario')
	    						  ->render(); 
		$this->template->header  = View::factory('blocks/pagina_header', $ko3_inner)
	                              ->render();
	    $this->template->footer  = View::factory('blocks/pagina_footer')
	                              ->render();                      
	    $this->template->content = View::factory('Formularios/FormularioDeAreaDeInteresse', $ko3)		
	    ->bind('errors', $this->errors)
	    ->bind('camposDoFormulario', $this->camposDoFormulario)                       
		->bind('formularioDeAreaDeInteresse', $this->formularioDeAreaDeInteresse);
	}


	public function action_validarForm(){

		$validator = new ValidadorDeFormularioDeAreaDeInteresse();
		$validator->verificarCamposValidos();
		$this->formularioDeAreaDeInteresse = new FormularioDeAreaDeInteresse();
		
		$acao = "";

		if (isset($_POST['form_button'])){
			$acao = $_POST['form_button'];
		}

		if($acao == "Proximo"){
			if(!$validator->isFormularioValido()){
				$this->errors = $validator->getErros();
				$this->camposDoFormulario = $validator->getCamposDoFormulario();
				$this->formularioDeAreaDeInteresse->recarregarDadosDoFormulario();
				$this->carregarFormulario();
			}
	
			else{
				$areaDeInteresse = $_POST['areaDeInteresse'];
				//$bd->insertAreaDeInteresse($areaDeInteresse);
				
				$_SESSION['areaDeInteresse'] = serialize($areaDeInteresse);
				
				//Elemento de visualização que junto ao $_SESSION['pagina_corrente'] define se a página
				//já foi validade e assim aparecerá no menu topo para seleção 
				$_SESSION['areaDeInteresse_validado'] = true;
				echo "<meta http-equiv=Refresh content=0;url=".url::site()."GerenciadorDeAtividades>";
			}
		}
		else if($acao == "Voltar"){
			$areaDeInteresse = "";
			if(isset($_POST['areaDeInteresse'])){
				$areaDeInteresse = $_POST['areaDeInteresse'];
			}
			
			//$bd->insertAreaDeInteresse($areaDeInteresse);
			
			$_SESSION['areaDeInteresse'] = serialize($areaDeInteresse);
			echo "<meta http-equiv=Refresh content=0;url=".url::site()."GerenciadorDeExperienciaProfissional>";
		}
		else{
			$this->carregarFormulario();
		}
	}
}

?>